const request = require('request')
const units = require('../units');
// const http = require('http');

// 对话核心模块
exports.AIvioce = async (req, res) => {
    const requestBody = req.body

    const options = {
        url: units.url + '/api/run_app',
        method: 'POST',
        headers: {
            "Authorization": `Bearer ${requestBody.access_token}`,
            "Content-Type": "application/json",
        },
        json: {
            "stream": true,
            "appcode": "036bf8b09cee40a7a0d0a53e0a65e152",
            "user_para": `{\"47a62458-e3bb-6b35-fb5d-d35369837b45\":{\"title\":\"输入\",\"value\":\"${requestBody.message}\"}}`
        }
    };
    const proxyReq = request(options);
    proxyReq.on('response', function (response) {
        response.pipe(res);
    });
    // res.stream(proxyReq)
    // request(options).then(resprst => {
    //     if (typeof resprst.data.status !== 'undefined') res.cc('错误')
    //     res.send(resprst.data)
    // })

    // let data = ''
    // const proqq = await request(options)
    // proqq.on('data', (response) => {
    //     data += response.data
    // })
    // res.send(data)
}